<template>
	<div class="sidebar">
		<el-menu :default-active="onRoutes" class="el-menu-vertical-demo" theme="dark" unique-opened router>
			<template v-for="item in items">
				<template v-if="item.children">
					<el-submenu :index="item.text">
						<template slot="title">
							<!-- <i :class="item.icon"></i> -->{{ item.text }}</template>
						<el-menu-item v-for="(subItem,i) in item.children" :key="i" :index="subItem.url">{{ subItem.text }}
						</el-menu-item>
					</el-submenu>
				</template>
				<template v-else>
					<el-menu-item :index="item.text">
						<!-- <i :class="item.icon"></i> -->{{ item.text }}
					</el-menu-item>
				</template>
			</template>
		</el-menu>
	</div>
</template>
<script>
	import {
		getMenuList
	}
	from '@/services/getData'
	export default {
		data() {
				return {
					items: []
				}
			},
			mounted() {
				this.initData();
			},
			computed: {
				onRoutes() {
					return this.$route.path.replace('/', '');
				}
			},
			methods: {
				async initData() {
					getMenuList()
						.then(res => {
							this.items = res
						}).catch(err => {
							console.log(err)
						})
				}
			}
	}
</script>
<style scoped>
	.sidebar {
		display: block;
		position: absolute;
		width: 250px;
		left: 0;
		top: 70px;
		bottom: 0;
		background: #2E363F;
	}

	.sidebar>ul {
		height: 100%;
		overflow-y: auto;
	}
</style>